package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.ao.FocusType;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.PageKey;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgFocus;
import com.ygqh.baby.service.YgFocusService;
import com.ygqh.baby.utils.JsonUtils;

@Controller
@RequestMapping("/admin/focus")
public class FocusController extends BaseController<Object, java.lang.Long>{
   @Autowired
	private YgFocusService ygFocusService;
	@RequestMapping("searchFocus")
	@ResponseBody
	public Map<String,Object> searchFocus(String q,QueryInfo queryInfo,FocusType focusType,PageKey pageKey)  {	
		
		ResultSet<YgFocus> resultSet=ygFocusService.search(queryInfo,q,focusType, pageKey);
		return resultSet.toDatatables(null);
	}
	@RequestMapping("saveFocus")
	@ResponseBody
	public Message saveFocus(String focus) {
		YgFocus ygfocus=JsonUtils.toObject(focus, YgFocus.class);		
		ygfocus.setCreateBy(getSession().getTrueName());
		ygfocus.setCreateTime(new Date());
	   return ygFocusService.saveOrUpdate(ygfocus)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
	
	@RequestMapping("updateFocus")
	@ResponseBody
	public Message updateFocus(Long id) {
		YgFocus ygfocus=new YgFocus();	
		ygfocus.setId(id);
		ygfocus.setStatus(DataStatus.Delete);
		ygfocus.setUpdateBy(getSession().getTrueName());
		ygfocus.setUpdateTime(new Date());
	   return ygFocusService.update(ygfocus)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
}
